package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author 西门凌兰
 * @version 1.0
 */
@Mapper
public interface UserMapper {

    /**
     * 根据openid查询用户信息
     * @param openid
     * @return
     */
    @Select("select * from user where openid = #{openid}")
    User getByOpenId(String openid);

    /**
     * 增加用户信息
     * @param user
     */
    void insert(User user);

    /**
     * 通过用户id查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    /**
     * 统计总用户
     * @param time
     * @return
     */
    @Select("select count(*) from user where create_time <= #{time} ")
    Integer countOldUsers(LocalDateTime time);

    /**
     * 统计
     * @param begin
     * @param end
     * @return
     */
    @Select("select count(*) from user where create_time between #{begin} and #{end}")
    Integer countNewUsers(LocalDateTime begin, LocalDateTime end);



}
